﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using PPIDesktopClient.Entities.Kml;
using PPIDesktopClient.Logic;
using ThirdPartyLibraries.GoogleEarth.Classes;

namespace PPIDesktopClient
{
    public partial class frmKml : DevComponents.DotNetBar.Office2007RibbonForm
    {
        public frmKml()
        {
            InitializeComponent();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            LSettings.Update(1, txtKml.Text);
            MessageBox.Show("KML information saved correctly");
        }

        private void btnDownload_Click(object sender, EventArgs e)
        {
            if(sfdDownload.ShowDialog() == DialogResult.OK)
            {
                List<EKmlFile> listKml = new List<EKmlFile>();
                listKml.Add(new EKmlFile( TypeKMLOfElement.CurrentPosition,"1",txtKml.Text));
                string _KMLCode = GEHelper.GenerateKMLFile(ref listKml);
                FileInfo newFile = new FileInfo(sfdDownload.FileName);
                if (newFile.Exists)
                {
                    newFile.Create();
                }
                GEHelper.WriteKMLFile(_KMLCode, newFile.FullName);
                MessageBox.Show("KML information saved correctly");
            } 
        }

        private void frmKml_Load(object sender, EventArgs e)
        {
            txtKml.Text = LSettings.SelectKML()[0].KMLCode;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
